<?php

namespace backend\models;

use Yii;

/**
 * This is the model class for table "config".
 *
 * @property string $id 配置ID
 * @property string $name 配置名称
 * @property int $type 配置类型
 * @property string $title 配置说明
 * @property int $group 配置分组
 * @property string $extra 配置值
 * @property string $remark 配置说明
 * @property string $create_time 创建时间
 * @property string $update_time 更新时间
 * @property int $status 状态
 * @property string $value 配置值
 * @property int $sort 排序
 */
class Config extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'config';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['type', 'group', 'create_time', 'update_time', 'status', 'sort'], 'integer'],
            [['value'], 'string'],
            [['name'], 'string', 'max' => 30],
            [['title'], 'string', 'max' => 50],
            [['extra'], 'string', 'max' => 255],
            [['remark'], 'string', 'max' => 100],
            [['name'], 'unique'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => 'Name',
            'type' => 'Type',
            'title' => 'Title',
            'group' => 'Group',
            'extra' => 'Extra',
            'remark' => 'Remark',
            'create_time' => 'Create Time',
            'update_time' => 'Update Time',
            'status' => 'Status',
            'value' => 'Value',
            'sort' => 'Sort',
        ];
    }
    
    
    
    public function getConfig($key){
        
        $query = static::find();
        
        $query->andWhere(['name'=>$key]);
        
        return $query->asArray()->one();
        
    }
}
